package com.ywu.bpmn.form.standard.service;

import com.ywu.bpmn.form.service.dto.YwuFormDefinitionDto;
import com.ywu.bpmn.form.service.dto.YwuFormDefinitionVersionDto;
import com.ywu.bpmn.form.service.entity.YwuFormDefinitionEntity;
import com.ywu.bpmn.form.service.service.YwuFormDefinitionService;
import com.ywu.common.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName YwuFormService
 * @Description TODO
 * @Author GroundDemo
 * @Date 2025/4/20 17:05
 * @Version 1.0
 **/
@Service
public class YwuFormService {
    @Autowired
    private YwuFormDefinitionService definitionService;

    /**
    * @Author GroundDemo
    * @Description 创建表单
    * @Date 17:08 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> createForm(YwuFormDefinitionDto dto) {
        // 流程处创建的表单，来源为FORM
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.createDefinition(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 修改表单信息
    * @Date 17:09 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> updateForm(YwuFormDefinitionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.updateDefinition(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 删除表单
    * @Date 17:10 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> deleteForm(YwuFormDefinitionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.deleteFormDefinition(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 分页查询表单列表
    * @Date 17:11 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> queryFormPageList(YwuFormDefinitionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.queryPageList(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询表单详情
    * @Date 17:12 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> queryFormInfo(YwuFormDefinitionDto dto) {
        return definitionService.queryFormEntity(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 修改表单json
    * @Date 17:13 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> updateFormJson(YwuFormDefinitionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.updateFormJson(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 发布表单
    * @Date 17:14 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> publishFormInfo(YwuFormDefinitionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.publishForm(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询历史版本列表
    * @Date 17:17 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> queryVersionList(YwuFormDefinitionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.queryFormVersionList(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询历史版本详情
    * @Date 17:18 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> queryVersionInfo(YwuFormDefinitionVersionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.queryVersionEntity(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 删除历史版本
    * @Date 17:18 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> deleteVersionInfo(YwuFormDefinitionVersionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.deleteVersion(dto);
    }

    /**
    * @Author GroundDemo
    * @Description 回退历史版本
    * @Date 17:19 2025/4/20
    * @Param [dto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    public CommonResult<Object> backVersionInfo(YwuFormDefinitionVersionDto dto) {
        dto.setSource(YwuFormDefinitionEntity.FORM_SOURCE);
        return definitionService.backVersion(dto);
    }
}
